#include "Shape.h"

using namespace Cartesia;

Shape::Shape(void)
{
	_shape = SHAPE_TRIANGLE;
	_color[0] = 0xff000000;
	_color[1] = 0xff000000;
	_color[2] = 0xff000000;
	_color[3] = 0xff000000;
}

Shape::~Shape(void)
{
}


//------------------------------------------------------------------------

void Shape::Draw()
{
	if (_visible)
	{
		Entity::Draw();

		if (_shape == SHAPE_TRIANGLE)
			Graphics::Draw(_vertices, D3DPT_TRIANGLELIST, 3);
		else if (_shape == SHAPE_QUAD)
			Graphics::Draw(_vertices, D3DPT_TRIANGLESTRIP, 4);
	}
}

//------------------------------------------------------------------------

// Asigna un color
void Shape::SetColor(DWORD color)
{
	_color[0] = color;
	_color[1] = color;
	_color[2] = color;
	_color[3] = color;
}

//------------------------------------------------------------------------

// Asigna forma (Triangulo o Cuadrado)
void Shape::SetShape(eShape eShapeType)
{
	_shape = eShapeType;
}


//------------------------------------------------------------------------

// Asigna las dimensiones (ancho y alto)
void Shape::SetDim(float w, float h)
{
	Entity::SetDim(w,h);
	SetShape(_shape);
}

//------------------------------------------------------------------------

void Shape::SetPos(float x, float y)
{
	Entity::SetPos(x, y);

	if (_shape == SHAPE_TRIANGLE)
	{
		_vertices[0].Set(_posX,			 _posY+_height/2, 1.0f, _color[0]);
		_vertices[1].Set(_posX-_width/2, _posY-_height/2, 1.0f, _color[1]);
		_vertices[2].Set(_posX+_width/2, _posY-_height/2, 1.0f, _color[2]);
	}
	else if (_shape == SHAPE_QUAD)
	{
		/*
		_vertices[0].Set(_posX-_width/2, _posY+_height/2, 1.0f, _color[0]);
		_vertices[1].Set(_posX+_width/2, _posY+_height/2, 1.0f, _color[1]);
		_vertices[2].Set(_posX-_width/2, _posY-_height/2, 1.0f, _color[2]);
		_vertices[3].Set(_posX+_width/2, _posY-_height/2, 1.0f, _color[3]);
		*/
		_vertices[0].Set(_posX,			_posY,			1.0f, _color[0]);
		_vertices[1].Set(_posX+_width,	_posY,			1.0f, _color[1]);
		_vertices[2].Set(_posX,			_posY+_height,	1.0f, _color[2]);
		_vertices[3].Set(_posX+_width,	_posY+_height,	1.0f, _color[3]);
	}
}

//------------------------------------------------------------------------

// Asigna colores individuales a los vertices del triangulo
bool Shape::SetColorPerVertex(DWORD color1, DWORD color2, DWORD color3)
{
	if (_shape != SHAPE_TRIANGLE)
		return false;

	_color[0] = color1;
	_color[1] = color2;
	_color[2] = color3;

	return true;
}

//------------------------------------------------------------------------

// Asigna colores individuales a los vertices del cuadrado
bool Shape::SetColorPerVertex(DWORD color1, DWORD color2, DWORD color3, DWORD color4)
{
	if (_shape != SHAPE_QUAD)
		return false;

	_color[0] = color1;
	_color[1] = color2;
	_color[2] = color3;
	_color[3] = color4;

	return true;
}

//------------------------------------------------------------------------

void Shape::Rotate(float angle)
{
	Entity::SetRotation(angle);
}